package com.basketball.gym.pojo;

import com.alibaba.excel.annotation.ExcelIgnore;
import com.baomidou.mybatisplus.annotation.IdType;

import java.time.LocalDateTime;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableLogic;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonBackReference;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import javax.validation.constraints.Max;
import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;

/**
 * <p>
 *
 * </p>
 *
 * @author 赵肖云
 * @since 2021-03-15
 */
@Data
@ApiModel(value = "User", description = "用户")
public class User implements Serializable {
    public interface update {
    }

    public interface Phone {
    }

    @ApiModelProperty(value = "更新时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime updateAt;

    @ApiModelProperty(value = "创建时间")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime createAt;

    @ApiModelProperty(value = "用户状态")
    @Min(value = 1, message = "state只能是1或2", groups = {update.class})
    @Max(value = 2, message = "state只能是1或2", groups = {update.class})
    private Integer state;

    @ApiModelProperty(value = "头像")
    private String avatarUrl;

    @ApiModelProperty(value = "国家")
    private String country;

    @ApiModelProperty(value = "城市")
    private String city;

    @ApiModelProperty(value = "省份")
    private String province;

    @ApiModelProperty(value = "性别")
    private Integer sex;

    @ApiModelProperty(value = "昵称")
    private String nickName;

    @ApiModelProperty(value = "openid")
    @JsonIgnore
    private String openId;

    @ApiModelProperty(value = "手机号")
    @NotNull(message = "手机号不能为空", groups = {Phone.class})
    private String phone;

    @ApiModelProperty(value = "用户ID")
    @NotNull(message = "id不能为空", groups = {update.class})
    @TableId(value = "id", type = IdType.AUTO)
    private Integer id;

    @TableField(exist = false)
    @ApiModelProperty(value = "角色")
    private List<Role> roles;

    @TableField(exist = false)
    @ApiModelProperty(value = "信息")
    private Information information;

    @TableField(exist = false)
    @JsonBackReference("当前页")
    @ApiModelProperty("当前页")
    private Integer current;

    @TableField(exist = false)
    @JsonBackReference("每页条数")
    @ApiModelProperty("每页条数")
    private Integer size;

    public User() {
    }

    public User(String openId) {
        this.openId = openId;
    }

    public User(Integer id, List<Role> roles) {
        this.id = id;
        this.roles = roles;
    }

    public void setWxInformation(Map<String, Object> data) {
        this.nickName = (String) data.get("nickName");
        this.avatarUrl = (String) data.get("avatarUrl");
    }
}
